<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="favicon.ico" >
    <link rel="Shortcut Icon" href="favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/public/lib/html5.js"></script>
    <script type="text/javascript" src="/public/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/public/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title></title>
    <meta name="keywords" content="洛阳易购商城">
    <meta name="description" content="洛阳易购商城">
</head>
<body>
<article class="cl pd-20">
    <form action="" method="post" class="form form-horizontal" id="">
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>优惠券名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" autocomplete="off" value="" placeholder="优惠券名称" class="input-text" id="activity_name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>满足金额：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" autocomplete="off" value="" placeholder="满足金额" class="input-text" id="satisfy_money">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>优惠金额：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" autocomplete="off" value="" class="input-text" placeholder="优惠金额" id="discount_money">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>开始时间：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="star_time" class="input-text Wdate" style="width:180px;">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>结束时间：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="end_time" class="input-text Wdate" style="width:180px;">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>优惠券数量：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="number" autocomplete="off" value="" class="input-text" placeholder="优惠券数量" id="count">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-2">是否启用：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="check-box">
                    <input type="checkbox" checked id="is_use">
                    <label for="is_use">&nbsp;</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<script type="text/javascript" src="/public/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/public/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/public/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="/public/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/public/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script src="/public/static/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/static/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
    });
    //模块输入信息验证
    function verify(activity_name,satisfy_money,discount_money,star_time,end_time,count) {
        if (activity_name == '') {
            layer.msg('请填写活动名称!',{icon:5,time:1000});
            return false;
        }
        if (satisfy_money == '') {
            layer.msg('请填写满足金额!',{icon:5,time:1000});
            return false;
        }
        if (discount_money == '') {
            layer.msg('请填写优惠金额!',{icon:5,time:1000});
            return false;
        }
        if (star_time == '') {
            layer.msg('请选择开始时间!',{icon:5,time:1000});
            return false;
        }
        if (end_time == '') {
            layer.msg('请选择结束时间!',{icon:5,time:1000});
            return false;
        }
        if (count == '') {
            layer.msg('请填写数量!',{icon:5,time:1000});
            return false;
        }
        return true;
    }
    var flag = false;//防止重复提交
    //添加用户
    function addSuppAjax() {
        var activity_name = $("#activity_name").val();
        var satisfy_money = $("#satisfy_money").val();
        var discount_money = $("#discount_money").val();
        var star_time = $("#star_time").val();
        var end_time = $("#end_time").val();
        var count = $("#count").val();
        if($("#is_use").prop("checked")){
            var is_use = 1;
        }else{
            var is_use = 0;
        }
        if(verify(activity_name,satisfy_money,discount_money,star_time,end_time,count) && !flag){
            flag = true;
            $.ajax({
                type : "post",
                url : "{:url('Activity/add_coupon')}",
                data : {
                    'activity_name':activity_name,
                    'satisfy_money' : satisfy_money,
                    'discount_money' : discount_money,
                    'star_time' : star_time,
                    'end_time' : end_time,
                    'is_use':is_use,
                    'count':count
                },
                success : function(data) {
                    if(data['code']>0){
                        layer.msg('添加成功!',{icon:1,time:1000},function () {
                            window.parent.location.reload();
                        });
                    }
                    else{
                        flag = false;
                        layer.msg(data['message'],{icon:5,time:1000});
                    }
                }
            });
        }
    }
</script>
</body>
</html>